package CustomDisplayMenu;
use strict;

sub replace_source {
    my ($cb, $app, $tmpl_ref) = @_;
    
    my $body = '<body id="<\$mt:var name="screen_id"\$>" class="';
    my $replace_body = '<body id="<$mt:var name="screen_id"$>" class="author-<$mt:var name="author_id"$> ';

    my $li = '<li<mt:if name="divider"> class="section"';
    my $replace_li = '<li id="<$mt:var name="id" lower_case="1" regex_replace="/:/","-"$>-menu"<mt:if name="divider"> class="section"';

    my $user_css = '<mt:SetVarBlock name="html_head" append="1"><link rel="stylesheet" href="<mt:StaticWebPath>plugins/CustomDisplayMenu/user.css" type="text/css" /></mt:SetVarBlock>';
    my $user_js = <<'EOT';
<mt:SetVarBlock name="js_include" append="1">
<script type="text/javascript">
/* <![CDATA[ */
var cdm_backup, cdm_blog, cdm_cfg_archives, cdm_cfg_comments, cdm_cfg_community_prefs, cdm_cfg_entry, cdm_cfg_plugin, cdm_cfg_plugins, cdm_cfg_prefs, cdm_cfg_registration, cdm_cfg_spam, cdm_cfg_system, cdm_cfg_system_feedback, cdm_cfg_system_general, cdm_cfg_system_users, cdm_cfg_trackbacks, cdm_cfg_web_services, cdm_comment_settings, cdm_create_new, cdm_dashboard, cdm_edit_author, cdm_edit_blog, cdm_edit_entry, cdm_edit_page, cdm_export, cdm_import, cdm_list, cdm_list_asset, cdm_list_author, cdm_list_blog, cdm_list_blogs, cdm_list_cat, cdm_list_category, cdm_list_comment, cdm_list_entry, cdm_list_field, cdm_list_folder, cdm_list_log, cdm_list_member, cdm_list_page, cdm_list_pages, cdm_list_ping, cdm_list_plugins, cdm_list_plugins, cdm_list_tag, cdm_list_template, cdm_list_user, cdm_list_widget, cdm_list_widget_set, cdm_main_screen, cdm_restore, cdm_start_backup, cdm_start_export, cdm_start_import, cdm_start_restore, cdm_stylecatcher_theme, cdm_system, cdm_system_check, cdm_tools, cdm_trackback_settings, cdm_view, cdm_view_log, cdm_dialog_asset_upload, cdm_start_upload, cdm_dialog_asset_options, cdm_upload_file, cdm_dialog_asset_list, cdm_dialog_asset_replace, cdm_list_assets, cdm_edit_asset;

var cdm_blog_1, cdm_blog_2, cdm_blog_3, cdm_blog_4, cdm_blog_5, cdm_blog_6, cdm_blog_7, cdm_blog_8, cdm_blog_9, cdm_blog_10;
<mt:Authors><mt:If name="__first__">var </mt:If>cdm_author_<mt:AuthorID><mt:Unless name="__last__">, </mt:Unless><mt:If name="__last__">;</mt:If></mt:Authors>
    cdm_author_<$mt:var name="author_id"$> = '1';
<mt:if name="system_overview_nav">
var cdm_system = '1';
<mt:else>
var cdm_blog = '1';
<mt:Blogs><mt:If name="__first__">var </mt:If>cdm_blog_<mt:BlogID><mt:Unless name="__last__">, </mt:Unless><mt:If name="__last__">;</mt:If></mt:Blogs>
    cdm_blog_<$mt:var name="blog_id"$> = '1';
</mt:if>
var cdm_<$mt:var name="screen_type" default="main-screen" regex_replace="/-| /g","_"$> = '1';
<mt:if name="new_object">var cdm_create_new = '1';</mt:if>
<mt:if name="mt_beta">var cdm_mt_beta = '1';</mt:if>
var cdm_<mt:var name="template_filename" escape="js" regex_replace="/-|\/|\./g","_"> = '1';
var cdm_<mt:Var name="mode"> = '1';
var cdm_<$mt:var name="screen_id" regex_replace="/-/g","_"$> = '1';
/* ]]> */
</script>
<script type="text/javascript" src="<mt:StaticWebPath>plugins/CustomDisplayMenu/user.js"></script>
</mt:SetVarBlock>
EOT
    
	$$tmpl_ref =~ s/$body/$replace_body/g;
	$$tmpl_ref =~ s/$li/$replace_li/g;
	$$tmpl_ref = $user_css . $user_js . $$tmpl_ref;	
}

1;
